<!-- 闪测问题表表单弹窗 -->
<form id="quicktest-form" lay-filter="quicktest-form" class="layui-form model-form" style="overflow:auto; height:500px;width:90%;">
    <input name="id" type="hidden"/>
    				    <div class="layui-form-item">
        <label class="layui-form-label">分类ID</label>
        <div class="layui-input-block">
            <!--<input name="typeId" placeholder="请输入分类ID" type="text" class="layui-input" maxlength="20"  id="typeId"-->
                   <!--lay-verify="required" required/>-->
            <!--<div id="selectCG"></div>-->
            <select name="typeId"  id="typeId"  >

            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">闪测标题</label>
        <div class="layui-input-block">
            <input name="title" placeholder="请输入闪测标题" type="text" class="layui-input" maxlength="200"  id="title"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副标题</label>
        <div class="layui-input-block">
            <input name="subtitle" placeholder="请输入闪测副标题" type="text" class="layui-input" maxlength="20"  id="subtitle"
                   lay-verify="required" required/>
        </div>
    </div>
 		    <div class="layui-form-item">
        <label class="layui-form-label">是否热门</label>
        <div class="layui-input-block" style="margin-right: 5%;">
            <!--<input name="hot" placeholder="请输入是否热门,0-否，1-是" type="text" class="layui-input" maxlength="20"  id="hot"-->
                   <!--lay-verify="required" required/>-->
            <select name="hot">
                <option value="0">否</option>
                <option value="1">是</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目图标</label>
        <div class="layui-input-block">
            <!--<input name="image" placeholder="请输入图片" type="text" class="layui-input" maxlength="20"  id="image"-->
                   <!--lay-verify="required" required/>-->
            <input type="hidden" name="image"   id="uploadPath" class="layui-input"     />
            <img id="uploadimg" src="" width="50" />

            <button type="button" class="layui-btn"  id="uploadUrl"   lay-filter="uploadFile">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目BANNER大图(建议640*400)</label>
        <div class="layui-input-block">
            <!--<input name="image" placeholder="请输入图片" type="text" class="layui-input" maxlength="20"  id="image"-->
            <!--lay-verify="required" required/>-->
            <input type="hidden" name="bannerImage"   id="uploadPath1" class="layui-input"     />
            <img id="uploadimg1" src="" width="50" />

            <button type="button" class="layui-btn"  id="uploadUrl1"   lay-filter="uploadFile1">
                <i class="layui-icon">&#xe67c;</i>选择图片
            </button>
        </div>
    </div>
 		    <div class="layui-form-item">
        <label class="layui-form-label">内容描述</label>
        <div class="layui-input-block">
            <input name="description" placeholder="请输入内容描述" type="text" class="layui-input" maxlength="2048"  id="description"
                   lay-verify="required" required/>
        </div>
    </div>
 		    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">测试人数</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input name="testPeoplenum" placeholder="请输入测试人数" type="text" class="layui-input" maxlength="20"  id="testPeoplenum"-->
                   <!--lay-verify="required" required/>-->
        <!--</div>-->
    <!--</div>-->
 		    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">评价人数</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input name="evalPeoplenum" placeholder="请输入评价人数" type="text" class="layui-input" maxlength="20"  id="evalPeoplenum"-->
                   <!--lay-verify="required" required/>-->
        <!--</div>-->
    <!--</div>-->
 		    <div class="layui-form-item">
        <label class="layui-form-label">闪问原价</label>
        <div class="layui-input-block">
            <input name="originalPrice" placeholder="请输入闪问原价" type="text" class="layui-input" maxlength="20"  id="originalPrice"
                   lay-verify="required" required/>
        </div>
    </div>
 		    <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label">创建时间</label>-->
        <!--<div class="layui-input-block">-->
            <!--<input name="createDate" placeholder="请输入创建时间" type="text" class="layui-input" maxlength="20"  id="createDate"-->
                   <!--lay-verify="required" required/>-->
        <!--</div>-->
    <!--</div>-->
 		    <div class="layui-form-item">
        <label class="layui-form-label">折扣价</label>
        <div class="layui-input-block">
            <input name="discountPrice" placeholder="请输入折扣价" type="text" class="layui-input" maxlength="20"  id="discountPrice"
                   lay-verify="required" required/>
        </div>
    </div>
     <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="user-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'config','admin', 'form', 'formSelects','xmSelect','upload'], function () {
        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;
        var formSelects = layui.formSelects;
        var upload=layui.upload;
        var config = layui.config;

        // var selectCG = xmSelect.render({
        //     el: '#selectCG',
        //     language: 'zn',
        //     name: 'categoryIds',
        //     data: [  ]
        // });
        form.render();
        var quicktest = admin.getTempData('t_quicktest');
           if (quicktest.method=="update"){
               console.log(quicktest)
        	form.val('quicktest-form', quicktest);
            $("#uploadimg").attr("src",quicktest.image);
               $("#uploadimg1").attr("src",quicktest.bannerImage);
            form.render();
        }
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
             layer.load(2);
            console.log("--------submit...........")
             console.log(data)
            // return false;

            // data.field.hot=data.field.isHot;

            admin.req('business/quicktest/'+quicktest.method, JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, {icon: 1, time: 500});
                   admin.finishPopupCenter();
                } else {
                    layer.msg(data.msg, {icon: 2, time: 500});
                }
            }, "post");  
            return false;
        });

           //获取闪测问题分类
        admin.req("/business/quicktestype/list",{},function(e){
            console.log(e)
            if(e.code==0&&e.size>0){
             //   var list=[];
                for ( var i in e.data) {
                    if(i=="remove")continue;
                   // var o={name:e.data[i].title,value:e.data[i].id};
                  //  list.push(o);
                    $("#typeId").append("<option value='"+e.data[i].id+"'> "+e.data[i].title+"</option>")
                }
               // form.val('quicktest-form', quicktest);
                admin.formLoad('#quicktest-form', quicktest)
                form.render();
              //  selectCG. update({data:list});
            }

        } );

        //创建一个上传组件 remarkuploadUrl
        upload.render({
            elem: '#uploadUrl'
            ,url:config.base_server+'file/uploadFile'
            ,accept: "images"
            ,before: function(o){
                console.log(o)
            }
            ,done: function(res, index, upload){ //上传后的回调
                if(res.code==0){
                    $('#uploadimg').attr("src", res.data.url);
                    $('#uploadPath').val(res.data.url);
                }
            }
        });

        //创建一个上传组件 remarkuploadUrl
                upload.render({
                    elem: '#uploadUrl1'
                    ,url:config.base_server+'file/uploadFile'
                    ,accept: "images"
                    ,before: function(o){
                        console.log(o)
                    }
                    ,done: function(res, index, upload){ //上传后的回调
                        if(res.code==0){
                            $('#uploadimg1').attr("src", res.data.url);
                            $('#uploadPath1').val(res.data.url);
                        }
                    }
                })
    });
</script>
